/*
 * @Description: 应用
 * @Author: bxsdhx
 * @Date: 2023-08-29 11:01:05
 * @LastEditTime: 2024-02-23 12:55:33
 * Copyright (C) 2023 bxsdhx. All rights reserved.
 */
import { defineStore } from "pinia";

export default defineStore("app", {
  /**
   * 数据
   */
  state() {
    return {
      /**
       * 程序名称
       */
      name: "jjp_vue-template",
      /**
       * 是否暗黑风格
       */
      isThemeDark: false,
    };
  },
  /**
   * 数据计算
   */
  getters: {},
  /**
   * 内部函数
   */
  actions: {
    /**
     * @description: 设置主题风格
     * @return {void}
     */
    setThemeDark(val: any): void {
      this.isThemeDark = Boolean(val);
      const element = document.querySelector("html");
      if (!element) return;
      if (this.isThemeDark) {
        element.classList.add("dark");
      } else {
        element.classList.remove("dark");
      }
      // 避免对其他文本造成样式干扰
      window.getSelection()?.removeAllRanges();
    },
  },
  /**
   * 持久化配置
   */
  persist: {},
});
